<?php
require("global.php");
if(isset($phprpg->input['equip'])){
	$query = $db->select("inventory","*","pid=".$phprpg->player['pid']." AND id=".intval($phprpg->input['equip']));
	if($db->recordcount($query) == 1){
//				$unequip = $db->getone("select items.id from `items`, `blueprint_items` where items.item_id = blueprint_items.id and blueprint_items.type=(select `type` from `blueprint_items` where `id`=?) and items.player_id=? and `status`='equipped'", array($item['item_id'], $player->id));
		$inv = $db->fetchrow($query);
		if($inv['equipped'] == 0){
			$checkItems = $db->query("select ".DB_PRE."inventory.id from ".DB_PRE."inventory, ".DB_PRE."items where ".DB_PRE."inventory.iid = ".DB_PRE."items.id and ".DB_PRE."items.type=(select `type` from ".DB_PRE."items where id={$inv['iid']}) and ".DB_PRE."inventory.pid={$phprpg->player['pid']} and equipped=1");
			if($db->recordcount($checkItems) == 0){
				$getItem = $db->select("items","*","id=".$inv['iid']);
				$i = $db->fetchrow($getItem);
				if($i['minstr'] > $phprpg->player['strength']){
					$error[] = "You do not have enough strength to equip this item.";
				}
				if($i['minagi'] > $phprpg->player['agility']){
					$error[] = "You do not have enough agility to equip this item.";
				}
				if($i['mindef'] > $phprpg->player['defense']){
					$error[] = "You do not have enough defense to equip this item.";
				}
				if($i['minlevel'] > $phprpg->player['level']){
					$error[] = "You do not have a high enough level to equip this item.";
				}
				if(!isset($error)){
					$update['equipped'] = 1;
					$db->update("inventory",$update,"id=".$inv['id']);
				}
			}else{
				$error[] = "You already have an item of this type equipped";
			}
		}else{
			$update['equipped'] = 0;
			$db->update("inventory",$update,"id=".$inv['id']);
		}
		if(isset($error)){
			$errors = $phprpg->inline_error($error);
		}
	}
}
$query = $db->select("inventory","*","pid=".$phprpg->player['pid']);
while($inv = $db->fetchrow($query)){
	$getItem = $db->select("items","*","id=".$inv['iid']);
	$i = $db->fetchrow($getItem);
	if($inv['equipped'] == 1){
		$i['status'] = "Equipped";
		$equip = "Unequip";
	}else{
		$i['status'] = "Unequipped";
		$equip = "Equip";
	}
	eval("\$items .= \"".$templates->get("inventory_item")."\";");
}
eval("\$inventory = \"".$templates->get("inventory")."\";");
$templates->output($inventory);
?>